<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 先用js封装一个类 模拟ES6中的 set  写入方法最后和es6的set对比
      class MySet {
        items = {}
        add(element){
          if(!this.has(element)){
            this.items[element] = element
            return element
          }
          return undefined
        }
        delete(value){
          if(this.has(value)){
            delete this.items[value]
            return true
          }
          return false
        }
        has(element){
          return element in this.items

        }
        clear(){
          this.items = {}
        }
        size(){
          return Object.keys(this.items).length
        }
        values(){
          return Object.values(this.items)
        }
      }
      const myset = new MySet()

      // 使用场景  数组去重
      const arr = ['1' , '1' , 'm' , '2' ,'w' , '9' , '3' , '3' , 'm' ,'s']
      arr.forEach(item => myset.add(item))
      console.log(myset.values());

    </script>
  </body>
</html>
